﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Domain;
using Persistence.Dao;
using Persistence;
namespace web.manage
{
    public partial class Product_Product_Manage : adminBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        private void bind()
        {
            int recordCount = Singleton<ProductDao>.Instance.GetCount();
            if(recordCount>0)
            {
                IList<Product> list = Singleton<ProductDao>.Instance.GetModels("*", "1=1", "[productId] desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
                if (list.Count > 0)
                {
                    repList.DataSource = list;
                    repList.DataBind();
                    AspNetPager1.RecordCount = recordCount;
                }
            }
           
        }

        protected string GetTypeName(object typeID)
        {
            if (typeID == null) return string.Empty;
            ProductType type
            = Singleton<ProductTypeDao>.Instance.GetModel(Common.Utils.StrToInt(typeID.ToString(), 0));
            if(type!=null)
            {
                return type.productTypeName;
            }
            return string.Empty;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = Common.Utils.StrToInt(e.CommandArgument, 0);
            if (id > 0)
            {
                Product p = new Product();
                p.productId = id;
                Singleton<ProductDao>.Instance.Delete(p);
                Common.Message.alert("删除成功");
                bind();
            }
        }
         
    }
}
